#!/usr/bin/python
#
# Copyright (C) 2008 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

""" Contains the objects required for RATS src resource access. """

try:
  from xml.etree import cElementTree as ElementTree
except ImportError:
  try:
    import cElementTree as ElementTree
  except ImportError:
    from elementtree import ElementTree

import ratom
import rawsc
from rawsc import RAWS_NAMESPACE
from rawsc.rats import *

class SrcParams(rawsc.RawsParams):
    _children = {}
    _children['{%s}filename' % RAWS_NAMESPACE] = ('filename', Filename)
    _children['{%s}updated' % RAWS_NAMESPACE] = ('updated', Updated)
    _children['{%s}to_be_removed' % RAWS_NAMESPACE] = ('to_be_removed', ToBeRemoved)
    _children['{%s}original_location' % RAWS_NAMESPACE] = ('original_location', OriginalLocation)

    def __init__(self, filename=None, updated=None, to_be_removed=None, original_location=None):
        rawsc.RawsParams.__init__(self, extension_elements=None, extension_attributes=None)
        self.filename = Filename(text = filename)
        self.updated = Updated(text = updated)
        self.to_be_removed = ToBeRemoved(text = to_be_removed)
        self.original_location = OriginalLocation(text = original_location)

def SrcParamsFromString(xml_string):
    return ratom.CreateClassFromXMLString(SrcParams, xml_string)   


class SrcContent(rawsc.RawsContent):
    """The atom:content element"""
    _children = ratom.AtomBase._children.copy()
    _children['{%s}params' % (RAWS_NAMESPACE)] = ('params', SrcParams)
    
    params = None
    
    def __init__(self, params=None):
        rawsc.RawsContent.__init__(self, extension_elements=None, extension_attributes=None)
        self.params = Params()
        if params:
            self.params = params
    
def SrcContentFromString(xml_string):
    return ratom.CreateClassFromXMLString(SrcContent, xml_string)   
    

class SrcEntry(rawsc.RawsEntry):
    """Represents a RATS src profile."""
    _children = rawsc.RawsEntry._children.copy()
    _children['{%s}content' % ratom.ATOM_NAMESPACE] = ('content', SrcContent)

    def __init__(self, author=None, category=None, atom_id=None, link=None, published=None, title=None, updated=None, content = None, extension_elements=None, extension_attributes=None):
        rawsc.RawsEntry.__init__(self, author=author, category=category, atom_id=atom_id, link=link, published=published, title=title, updated=updated,
                                extension_elements=extension_elements, extension_attributes=extension_attributes)
        self.content = SrcContent()
        if content:
            self.content = content

def SrcEntryFromString(xml_string):
    return ratom.CreateClassFromXMLString(SrcEntry, xml_string)
    

class SrcFeed(rawsc.RawsFeed, rawsc.LinkFinder):
    """Represents a RATS  feed."""
    _children = rawsc.RawsFeed._children.copy()
    _children['{%s}entry' % ratom.ATOM_NAMESPACE] = ('entry', [SrcEntry])

def SrcFeedFromString(xml_string):
  return ratom.CreateClassFromXMLString(SrcFeed, xml_string)

